#include "PreFracturedCuboid.h"

PreFracturedCuboid::PreFracturedCuboid()
{

}

PreFracturedCuboid::PreFracturedCuboid(const Vec3f& pos, const Vec3f& halfExtents, int numFragments)
{
	m_halfExtents = halfExtents;

	

	btVector3 bbmax(m_halfExtents.X, m_halfExtents.Y, m_halfExtents.Z);
	btVector3 bbmin = -bbmax;
	btVector3 bbt(pos.X, pos.Y, pos.Z);
	btVector3 diff = bbmax - bbmin;
	btAlignedObjectArray<btVector3> points;
	btVector3 point;
	btQuaternion bbq;
	bbq.normalize();

	//btQuaternion bbq = m_pRigidBody->getOrientation();

	for (int i=0; i < numFragments; i++) 
	{

		// Place points within box area (points are in world coordinates)
		point = quatRotate(bbq, btVector3(btScalar(rand() / btScalar((float)RAND_MAX)) * diff.x() -diff.x()/2., btScalar(rand() / btScalar((float)RAND_MAX)) * diff.y() -diff.y()/2., btScalar(rand() / btScalar((float)RAND_MAX)) * diff.z() -diff.z()/2.)) + bbt;
		points.push_back(point);
	}


	voronoiBBShatter( points, bbmin, bbmax, bbq, bbt, 1, m_pRigidBody->getLinearVelocity());
}

void PreFracturedCuboid::Collided(btManifoldPoint& contact)
{

}

void PreFracturedCuboid::Update()
{

}